package com.pos.clothes.service.serviceImpl;

import com.pos.clothes.mapper.DiscountMapper;
import com.pos.clothes.pojo.Discount;
import com.pos.clothes.service.DiscountService;
import com.pos.clothes.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DiscountServiceImpl implements DiscountService {
    @Autowired
    private DiscountMapper mapper;

    @Override
    public Discount getAllDiscount() {
        return mapper.getAllDiscount();
    }

    @Override
    public List<Discount> getBorderDiscount() {
        return mapper.getBorderDiscount();
    }

    @Override
    public Integer updateAllDiscount(Discount discount) {
        return mapper.updateAllDiscount(discount);
    }

    @Override
    public Object updateBorderDiscount(List<Discount> discounts) {
        try{
            for (int i=0;i<3;i++){
                mapper.updateBorderDiscount(discounts.get(i));
            }
        }catch (Exception e){
            return JsonData.buildError("更改失败");
        }
        return JsonData.buildSuccess("更新成功","ok");
    }


}

